import 'dart:convert' show json;

class DownloadInfoResult {
  int? cursor;
  int? err;
  String? errMsg;
  String? token;
  DownloadInfo? data;
  String? url;

  DownloadInfoResult.fromParams(
      {this.cursor, this.err, this.errMsg, this.token, this.data});

  factory DownloadInfoResult(Object jsonStr) => jsonStr is String
      ? DownloadInfoResult.fromJson(json.decode(jsonStr))
      : DownloadInfoResult.fromJson(jsonStr);

  static DownloadInfoResult? parse(jsonStr) =>
      ['null', '', null].contains(jsonStr) ? null : DownloadInfoResult(jsonStr);

  DownloadInfoResult.fromJson(jsonRes) {
    cursor = jsonRes['cursor'];
    err = jsonRes['err'];
    errMsg = jsonRes['err_msg'];
    token = jsonRes['token'];
    data =
        jsonRes['data'] == null ? null : DownloadInfo.fromJson(jsonRes['data']);
  }

  @override
  String toString() {
    return '{"cursor": $cursor, "err": $err, "err_msg": ${errMsg != null ? '${json.encode(errMsg)}' : 'null'}, "token": ${token != null ? '${json.encode(token)}' : 'null'}, "data": $data}';
  }

  String toJson() => this.toString();
}

class DownloadInfo {
  String? background;
  String? desc;
  String? duration;
  String? title;
  List<DownloadType?>? downloadTypes;

  DownloadInfo.fromParams(
      {this.background,
      this.desc,
      this.duration,
      this.title,
      this.downloadTypes});

  DownloadInfo.fromJson(jsonRes) {
    background = jsonRes['background'];
    desc = jsonRes['desc'];
    duration = jsonRes['duration'];
    title = jsonRes['title'];
    downloadTypes = jsonRes['downloadTypes'] == null ? null : [];

    for (var downloadTypesItem
        in downloadTypes == null ? [] : jsonRes['downloadTypes']) {
      downloadTypes!.add(downloadTypesItem == null
          ? null
          : DownloadType.fromJson(downloadTypesItem));
    }
  }

  @override
  String toString() {
    return '{"background": ${background != null ? '${json.encode(background)}' : 'null'}, "desc": ${desc != null ? '${json.encode(desc)}' : 'null'}, "duration": ${duration != null ? '${json.encode(duration)}' : 'null'}, "title": ${title != null ? '${json.encode(title)}' : 'null'}, "downloadTypes": $downloadTypes}';
  }

  String toJson() => this.toString();
}

class DownloadType {
  String? name;
  String? size;
  String? url;

  DownloadType.fromParams({this.name, this.size, this.url});

  DownloadType.fromJson(jsonRes) {
    name = jsonRes['name'];
    size = jsonRes['size'];
    url = jsonRes['url'];
  }

  @override
  String toString() {
    return '{"name": ${name != null ? '${json.encode(name)}' : 'null'}, "size": ${size != null ? '${json.encode(size)}' : 'null'}, "url": ${url != null ? '${json.encode(url)}' : 'null'}}';
  }

  String toJson() => this.toString();
}
